package com.vx.listener;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.vx.FlowCode;
import com.vx.service.IUserService;
import com.vx.service.IWorkflowService;
import com.vx.service.impl.UserServiceImpl;
import com.vx.util.SpringContextUtils;
import com.vx.vo.RoleVO;
import com.vx.vo.UserVO;

@SuppressWarnings("serial")
public class KZlistener implements TaskListener{

	@Override
	public void notify(DelegateTask delegateTask) {
		IUserService useService=(IUserService) SpringContextUtils.getBean("userService");
		HttpSession session=((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest().getSession();
		UserVO user=(UserVO) session.getAttribute("user");
		RoleVO role=useService.getRole(user.getUserCode());
		int roleId=role.getId()+1;
		RoleVO leaderRole=useService.getRole(roleId);
		List<Map<String, Object>> assigneeList=useService.getRoleUser(leaderRole.getRoleCode());
		for (Map<String, Object> map : assigneeList) {
			//设置审批人
			delegateTask.addCandidateUser((String)map.get("usercode"));
		}
		//设置审批人
//		delegateTask.setAssignee(assignee);
	}
}
